﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ScFramework.Core;
using UnityEngine.UI;
public class EntityPropertyLogic : LogicModuleBase, ICombineSubUI
{
    GameObject target;
    List<MeshEntityData> currentEntity;

    static List<string> UIProperties = new List<string>
    {
        "血量",
        "防御",
        "质量",
        "锋利"
    };

    static List<int> selList;

    public void InitGameobject(List<GameObject> obj)
    {
        target = obj.Find(s => s.name == "EntityProperty");
        currentEntity = new List<MeshEntityData>();
    }

    public override void OnEnable()
    {
        base.OnEnable();
        target.SetActive(true);
    }
    public override void OnDisable()
    {
        base.OnDisable();
        target.SetActive(false);
    }

    [RegisterEvent(CombineUIEvent.Receive_Data)]
    void Refresh(List<MeshEntityData> datas)
    {
        currentEntity = new List<MeshEntityData>(datas);
#if TEST_UI_F
        Debug.Log("PropertyRefreshed");
        Debug.Log(datas.Count);
#endif
    }


    [RegisterEvent(CombineUIEvent.ShowObjectValues)]
    void ShowEntitySelected(int id)
    {
        target.transform.Find("LowerText").GetComponent<Text>().text = default;
        target.transform.Find("UpperText").GetComponent<Text>().text = default;

        if (id <= 0 || id >= currentEntity.Count)
        {
            return;
        }

        MeshEntityData selected = null;
        selected = currentEntity.Find(x => x.ID == id);
#if TEST_UI_F
        Debug.Log("DEBUG : " + selected.Name + " is selected");
#endif
        target.transform.Find("UpperText").GetComponent<Text>().text = selected.Body.Abstract;

        selList = new List<int>         //high shit warning
        {   selected.Values.Blood,
            selected.Values.Defence,
            selected.Values.Mass,
            selected.Values.Sharpness
        };

#if TEST_UI_F
        Debug.Log("----------------------------------");
#endif
        for (int i = 0; i < selList.Count; i++)
        {
#if TEST_UI_F
            Debug.Log(UIProperties[i].ToString() + " : " + selList[i].ToString());
#endif
            target.transform.Find("LowerText").GetComponent<Text>().text += UIProperties[i].ToString();
            target.transform.Find("LowerText").GetComponent<Text>().text += "\t";
            target.transform.Find("LowerText").GetComponent<Text>().text += selList[i].ToString();
            target.transform.Find("LowerText").GetComponent<Text>().text += "\r\n";
        }
#if TEST_UI_Fs
        Debug.Log("----------------------------------");
#endif
    }

}